import 'package:flutter/material.dart';
import '../settingPage.dart';

class LoveMySelf extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _LoveMySelfState();
  }
}

class _LoveMySelfState extends State<LoveMySelf> {
  final List<Map> _favourite = <Map>[
    {'title': '浏览记录', 'icon': Icons.history},
    {'title': '我的收藏', 'icon': Icons.favorite},
    {'title': '我的动态', 'icon': Icons.assessment},
    {'title': '我的发布', 'icon': Icons.text_fields}
  ];
  final TextEditingController _descController = new TextEditingController();

  String _name = 'Chengcheng ZHOU';
  String _description = '如果人没有的梦想，那和咸鱼有什么区别？';
  int _fans = 10000;
  int _subscription = 100;

  void handleChangeDesc(value) {
    String desc = value;
    if (desc == null) {
      desc = _descController.text.trim() == '' ? '心如止水。' : _descController.text.trim();
    }
    setState(() {
      _description = desc;
    });
    _descController.clear();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      backgroundColor: Colors.white,
      appBar: new AppBar(
        title: new Text(_name),
        actions: <Widget>[
          new Container(
            padding: const EdgeInsets.symmetric(horizontal: 6.0),
            child: new IconButton(
              icon: new Icon(Icons.settings),
              onPressed: () {
                Navigator.push(
                  context,
                  new MaterialPageRoute<void>(
                    builder: (BuildContext context) => new Setting(),
                    fullscreenDialog: true,
                  ),
                );
              },
            ),
          ),
        ],
      ),
      body: new Column(
        children: <Widget>[
          new Expanded(
            child: new Container(
              child: new Container(
                child: new Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    new Container(
                      alignment: Alignment.center,
                      child: new Image.asset(
                        'images/timg.jpg',
                        fit: BoxFit.fill,
                        height: 300.0,
                      ),
                    ),
                    new Container(
                      padding: const EdgeInsets.symmetric(
                          horizontal: 15.0, vertical: 20.0),
                      child: new Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          new Text('粉丝：$_fans'),
                          new Text('关注：$_subscription'),
                          new Text('心情：$_description'),
                        ],
                      ),
                    ),
                    new ButtonTheme.bar(
                      child: new ButtonBar(
                        alignment: MainAxisAlignment.start,
                        children: <Widget>[
                          new FlatButton(
                            child: const Text('更新心情'),
                            textColor: Colors.amber.shade500,
                            onPressed: () {
                              showDialog<Null>(
                                context: context,
                                builder: (_) {
                                  return new AlertDialog(
                                    content: new TextField(
                                      controller: _descController,
                                      onSubmitted: handleChangeDesc,
                                    ),
                                    actions: <Widget>[
                                      new FlatButton(
                                        child: new Text('取消'),
                                        onPressed: () {
                                          Navigator.of(context).pop();
                                        },
                                      ),
                                      new FlatButton(
                                        child: new Text('确认'),
                                        onPressed: () {
                                          handleChangeDesc(null);
                                          Navigator.of(context).pop();
                                        },
                                      ),
                                    ],
                                  );
                                },
                              );
                            },
                          ),
                          new FlatButton(
                            child: const Text('更新封面'),
                            textColor: Colors.amber.shade500,
                            onPressed: () {},
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
      floatingActionButton: new FloatingActionButton(
        tooltip: 'Show explanation',
        backgroundColor: Colors.white,
        child: new Icon(
          Icons.bookmark,
          color: Colors.red,
        ),
        onPressed: () {
          showModalBottomSheet<void>(
            context: context,
            builder: (BuildContext context) {
              return new Container(
                height: 250.0, //10 - 10 - 2
                padding: const EdgeInsets.symmetric(vertical: 10.0),
                child: new Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    new Container(
                      height: 230.0,
                      alignment: Alignment.center,
                      child: new ListView.builder(
                        itemBuilder: (_, index) {
                          return new ListTile(
                            leading: new Icon(_favourite[index]['icon'],color: Colors.lightBlue,),
                            title: new Text(_favourite[index]['title']),
                            onTap: () {
                              Navigator.of(context).pop();
                            },
                          );
                        },
                        itemCount: _favourite.length,
                      ),
                    ),
                  ],
                ),
              );
            },
          );
        },
      ),
    );
  }
}
